package com.qt.generics;

import java.util.ArrayList;
import java.util.LinkedHashSet;

public class GenericsDemo02 {

    public static void main(String[] args) {

        GenericsDemo02 genericsDemo02 = new GenericsDemo02();
        genericsDemo02.me();


    }
    public  void me(){
        BsCat bosi = new BsCat("bosi", 11);
        LhCat lihua = new LhCat("lihua", 11);
        TdDog taidi = new TdDog("taidi", 11);
        HsqDog hsq = new HsqDog("hsq", 11);
        ArrayList<Cat> catList = new ArrayList<>();
        catList.add(lihua);
        catList.add(bosi);
        ArrayList<Dog> dogList = new ArrayList<>();
        dogList.add(taidi);
        dogList.add(hsq);
        ArrayList<Student> stu = new ArrayList<>();
        keepPet1(catList);
        keepPet2(dogList);

        keepPet3(catList);
        keepPet3(dogList);

    }


    public static void keepPet1(ArrayList<? extends Cat> list){
        for (Cat cat : list) {
            cat.eat();
        }
    }

    public static void keepPet2(ArrayList<? extends Dog> list){
        for (Dog dog : list) {
            dog.eat();
        }
    }

    public static void keepPet3(ArrayList<? extends Animal> list){
        for (Animal animal : list) {
            animal.eat();
        }
    }

static class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

abstract class  Animal{
        private String name;
        private int age;
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public abstract void eat();
}

abstract class Cat extends Animal{


    public Cat(String name, int age) {
        super(name, age);
    }

}

 class BsCat extends Cat{
    @Override
    public void eat() {
        System.out.println("波斯猫");
    }
    public BsCat(String name, int age) {
        super(name, age);
    }
}

     class LhCat extends Cat{
        @Override
        public void eat() {
            System.out.println("狸花猫");
        }
        public LhCat(String name, int age) {
            super(name, age);
        }
    }

    abstract class Dog extends Animal{


        public Dog(String name, int age) {
            super(name, age);
        }
    }

     class TdDog extends Dog{
        @Override
        public void eat() {
            System.out.println("泰迪狗");
        }
        public TdDog(String name, int age) {
            super(name, age);
        }
    }

     class HsqDog extends Dog{
        @Override
        public void eat() {
            System.out.println("哈士奇");
        }

        public HsqDog(String name, int age) {
            super(name, age);
        }
    }





}
